<?php

Yii::import( "ext.xupload.models.XUploadForm" );
Yii::import( "ext.xupload.models.ImageUploadForm" );
Yii::import( "application.controllers.FrontendBaseController" );

class XUploadController extends FrontendBaseController
{

    public function actions()
    {
        return array(
            'upload' => array(
                'class' => 'ext.xupload.actions.XUploadAction',
                'path' => Yii::app()->getBasePath() . "/../uploads/imgs",
            ),
        );
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {
        $model = new XUploadForm;
        $this->render( 'index', array(
            'model' => $model,
        ) );
    }

    public function actionSingle()
    {
        $model = new XUploadForm;
        $this->render( 'single', array(
            'model' => $model,
        ) );
    }

    /**
     * Single queued file upload
     */
    public function actionQueue()
    {
        $model = new XUploadForm;
        $this->render( 'queue', array(
            'model' => $model,
        ) );
    }

    /**
     * Single queued file upload
     */
    public function actionMultiple()
    {
        $model = new XUploadForm;
        $this->render( 'multiple', array(
            'model' => $model,
        ) );
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError()
    {
        if ( $error = Yii::app()->errorHandler->error )
        {
            if ( Yii::app()->request->isAjaxRequest )
                echo $error[ 'message' ];
            else
                $this->render( 'error', $error );
        }
    }

}